<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="180px" label-position="right" :disabled="!!isDetail" >
				<el-col :span="24">
					<el-form-item label="承诺卡编号" prop="cnkbh" >
						<el-input v-model="dataForm.cnkbh" placeholder="请输入承诺卡编号" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="承诺人" prop="cnr" >
						<el-select v-model="dataForm.cnr" placeholder="请选择承诺人" clearable :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in cnrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="承诺日期" prop="cnrq" >
						<el-date-picker v-model="dataForm.cnrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="特级动火数量" prop="tjdh" >
						<el-input v-model="dataForm.tjdh" placeholder="请输入特级动火数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="二级动火数量" prop="ejdh" >
						<el-input v-model="dataForm.ejdh" placeholder="请输入二级动火数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盲板抽堵数量" prop="mbcd" >
						<el-input v-model="dataForm.mbcd" placeholder="请输入二级动火数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="吊装数量" prop="dzsl" >
						<el-input v-model="dataForm.dzsl" placeholder="请输入吊装数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="动土数量" prop="dtsl" >
						<el-input v-model="dataForm.dtsl" placeholder="请输入动土数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="检维修数量" prop="jwx" >
						<el-input v-model="dataForm.jwx" placeholder="请输入检维修数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="生产装置套数" prop="sczz" >
						<el-input v-model="dataForm.sczz" placeholder="请输入生产装置套数" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="停车套数" prop="tcts" >
						<el-input v-model="dataForm.tcts" placeholder="请输入停车套数" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否有承包商作业" prop="sfcbs" >
						<el-select v-model="dataForm.sfcbs" placeholder="请选择是否有承包商作业" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfcbsOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否有开停车" prop="sfkc" >
						<el-select v-model="dataForm.sfkc" placeholder="请选择是否有开停车" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfkcOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否有承包商作业（扩试）" prop="sfkzz" >
						<el-select v-model="dataForm.sfkzz" placeholder="请选择是否有承包商作业" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfkzzOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="一级动火数量" prop="yjdh" >
						<el-input v-model="dataForm.yjdh" placeholder="请输入一级动火数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="受限空间数量" prop="sxkj" >
						<el-input v-model="dataForm.sxkj" placeholder="请输入受限空间数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="高处作业数量" prop="gczy" >
						<el-input v-model="dataForm.gczy" placeholder="请输入高处作业数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="临时用电数量" prop="lsyd" >
						<el-input v-model="dataForm.lsyd" placeholder="请输入临时用电数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="断路数量" prop="dlsl" >
						<el-input v-model="dataForm.dlsl" placeholder="请输入断路数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="动火数量" prop="dhsl" >
						<el-input v-model="dataForm.dhsl" placeholder="请输入动火数量" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="运行套数" prop="yxts" >
						<el-input v-model="dataForm.yxts" placeholder="请输入运行套数" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否有试生产" prop="sfssc" >
						<el-select v-model="dataForm.sfssc" placeholder="请选择是否有试生产" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfsscOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否有重大隐患" prop="sfzdyh" >
						<el-select v-model="dataForm.sfzdyh" placeholder="请选择是否有重大隐患" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfzdyhOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="风险等级" prop="fxdj" >
						<el-select v-model="dataForm.fxdj" placeholder="请选择风险等级" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fxdjOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					cnkbh:undefined,
					cnr:undefined,
					cnrq:undefined,
					tjdh:undefined,
					ejdh:undefined,
					mbcd:undefined,
					dzsl:undefined,
					dtsl:undefined,
					jwx:undefined,
					sczz:undefined,
					tcts:undefined,
					sfcbs:undefined,
					sfkc:undefined,
					sfkzz:undefined,
					yjdh:undefined,
					sxkj:undefined,
					gczy:undefined,
					lsyd:undefined,
					dlsl:undefined,
					dhsl:undefined,
					yxts:undefined,
					sfssc:undefined,
					sfzdyh:undefined,
					fxdj:undefined,
        },
				cnrOptions:[],
				sfcbsOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfkcOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfkzzOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfsscOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfzdyhOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				fxdjOptions:[{"fullName":"重大风险","id":"1"},{"fullName":"较大风险","id":"2"},{"fullName":"一般风险","id":"3"},{"fullName":"低风险","id":"4"}],
      }
    },
    created() {
		  this.getcnrOptions();
    },
    methods: {
			getcnrOptions() {
				previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
					this.cnrOptions = res.data
				})
			},
			goBack() {
				this.$emit('refresh')
			},
      init(id, isDetail) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/aqscZrcnk/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/aqscZrcnk',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/aqscZrcnk/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },
    }
  }
  </script>